{include file="public/header" /}

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5">
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="title" placeholder="用户昵称|手机号" value="{:input('get.title')}"
                                autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="sreach">搜索</button>
                        </div>
                    </form>
                </div>

                <div class="layui-card-body layui-table-body layui-table-main">
                    <table class="layui-table layui-form">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>绑定店铺</th>
                                <th>推荐码</th>
                                <th>昵称</th>
                                <th>性别</th>
                                <th>头像</th>
                                <th>手机号</th>
                                <th>注册时间</th>
                                <th>订单记录</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            {foreach $list as $v}
                            <tr>
                                <td>{$v.id|default=''}</td>
                                <td>{$v.shopname|default=''}</td>
                                <td>{$v.code|default=0}</td>
                                <td>{$v.nickName|default=''}</td>
                                <td>{if $v.gender == 0}未知{elseif $v.gender == 1}男{else/}女{/if}</td>
                                <td>
                                    <div id="layer-photos" class="layer-photos">
                                        <img layer-pid="" layer-src="{$v.avatarUrl|default=''}"
                                            src="{$v.avatarUrl|default=''}" alt="{$v.nickName|default=''}">
                                    </div>
                                </td>
                                <td>{$v.mobile|default=0}</td>
                                <td>{$v.created|default=0}</td>
                                <td class="td-manage">
                                    <a title="查看" onclick="data_edit('查看','/shop/order?user_id={$v.id}')"
                                        href="javascript:;" class="layui-btn layui-btn-normal">
                                        查看
                                    </a>
                                </td>
                                <td class="td-manage">
                                    {if $v.shopid > 0}
                                    <a title="解绑商家" onclick="unshop('解绑商家','/user/unshopid_str',{$v.id},1)"
                                        href="javascript:;" class="layui-btn layui-btn-danger">
                                        解绑商家
                                    </a>
                                    {else /}
                                    <a title="绑定商家" onclick="unshop('绑定商家','/user/unshopid_str',{$v.id},2)"
                                        href="javascript:;" class="layui-btn layui-btn-normal">
                                        绑定商家
                                    </a>
                                    {/if}
                                </td>

                            </tr>
                            {/foreach}

                        </tbody>
                    </table>
                </div>
                <div class="layui-card-body">
                    <div class="page">
                        {$list->render()|raw}
                    </div>
                </div>

            </div>
        </div>
    </div>
</div>
</body>
<script>
    function unshop(title, url, id, type) {
        if (type == 1) {
            layer.confirm(title, { icon: 3, title: '提示' }, function (index) {
                $.ajax({
                    type: 'post',
                    url: url,
                    data: { id: id },
                    success: function (res) {
                        if (res.code == 0) {
                            layer.msg(res.msg, { icon: 6, time: 1000 }, function () {
                                layer.close(index);
                                // 获得frame索引
                                location.reload();
                            });
                        } else {
                            layer.msg(res.msg, { icon: 2, time: 1000 });
                        }
                    }
                });
                layer.close(index);
            });
        } else {
            var index = layer.open({
                content: '<div class="layui-inline layui-show-xs-block">' +
                    '<input type="text" name="account" placeholder="请填写商家账号" class="layui-input" />' +
                    '</div >',
                yes: function (index, layero) {
                    var account = $('input[name="account"]').val();
                    if (account.len <= 0) {
                        layer.msg('账号不能为空');
                    }
                    $.ajax({
                        type: 'post',
                        url: url,
                        data: { id: id, account: account },
                        success: function (res) {
                            if (res.code == 0) {
                                layer.msg(res.msg, { icon: 6, time: 1000 }, function () {
                                    layer.close(index);
                                    // 获得frame索引
                                    location.reload();
                                });
                            } else {
                                layer.msg(res.msg, { icon: 2, time: 1000 });
                            }
                        }
                    });
                    return false;
                }
            });
        }
    }
    layui.use(['form', 'upload'], function () {
        var $ = layui.jquery
            , form = layui.form
            , layer = layui.layer;
    });
</script>
<script>
    layer.photos({
        photos: '#layer-photos'
        , anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
    });
</script>
{include file="public/footer"}